package cn.wolfcode.trip.web.controller;

import cn.wolfcode.trip.base.domain.HotelDictionary;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IHotelDictionaryService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/hotelDictionary")
public class HotelDictionaryController {
    @Autowired
    private IHotelDictionaryService hotelDictionaryService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        model.addAttribute("result",hotelDictionaryService.query(qo));
        return "hotelDictionary/list";
    }

    @RequestMapping("/delete")
    @ResponseBody
    public JSONResult delete(Long id){
        JSONResult result = new JSONResult();

        try {
            hotelDictionaryService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("操作失败");
        }

        return result;
    }




    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(HotelDictionary hotelDictionary){
        JSONResult result = new JSONResult();
        try {

            hotelDictionaryService.saveOrUpdate(hotelDictionary);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("操作失败");
        }
        return result;
    }


}
